package org.example.service.impl;

import com.alibaba.nacos.api.utils.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.common.AppHttpCodeEnum;
import org.example.common.JwtService;
import org.example.common.ResponseResult;
import org.example.pojo.User;
import org.example.service.UserService;
import org.example.mapper.UserMapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* @author 贾媛婕
* @description 针对表【user】的数据库操作Service实现
* @createDate 2024-09-06 19:36:19
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Override
    public ResponseResult login(User user) {

        User one = this.getOne(Wrappers.<User>lambdaQuery().eq(StringUtils.isBlank(user.getUsername()), User::getUsername, user.getUsername()));

        if(one != null){
            Map<String,Object> map = new HashMap<>();
            map.put("user",one.getId());

            String token = JwtService.createToken(map);

            map.put("token",token);

            return ResponseResult.okResult(map);

        }


        return ResponseResult.errorResult(500,"失败");
    }
}




